'use static';

const fs = require('fs');
const { sequelize } = require('../db/db');



function getFiles() {

 
    let files = fs.readdirSync(__dirname);


    return files.filter((x) => {
        return x.endsWith('.js') && x !== "index.js";
    });
}



function RighterModel(files) {

    let obj = {};

    files.forEach(ele => {
        let key = ele.substring(0, ele.length - 3);


        obj[key] = require(__dirname + "/" + ele);
    });

    return obj;
}

let files = getFiles(__dirname);

let objMod = RighterModel(files);


objMod.sync = async () => {
    if (process.env === "process") {
        console.log("当前为生产环境,不可以强制建表");
    } else {
        return sequelize.sync({ force: true });
    }
}

module.exports = objMod